package 常用类.日期处理.test01;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest01 {
    public static void main(String[] args) throws ParseException {
        Date nowTime = new Date();
        System.out.println(nowTime);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        String nowTimeStr = sdf.format(nowTime);
        System.out.println(nowTimeStr);

        //将字符串转换为Date类型
        String time = "2020-10-14 19-35-45 574";
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss SSS");
        Date dateTime =  sdf2.parse(time);
        System.out.println(dateTime);
    }
}
